zz_

test/max.test.js

zzmq.dev@gmail.com[dev1]/mathkit[add-isperfectsquare-n-function-tests] / test / max.test.js @ c510a748 Download
Ladder Summary
  • file Provides a comprehensive test suite for the `max` function, covering typical usage (multiple numbers, negatives, mixed signs, single argument), edge cases (no arguments, presence of `NaN`, handling of `Infinity`), and large numeric values to ensure correct behavior without overflow.
 import { test } from "node:test";
 import assert from "node:assert/strict";
 import { max } from "../src/max.js";
 
 test("max returns the largest of multiple numbers", () => {
  assert.strictEqual(max(3, 1, 4, 2), 4);
 });
 
 test("max works with negative numbers", () => {
  assert.strictEqual(max(-7, -3, -10), -3);
 });
 
 test("max with mixed numbers", () => {
  assert.strictEqual(max(-2, 0, 5, -1), 5);
 });
 
 test("max with single argument returns that argument", () => {
  assert.strictEqual(max(99), 99);
 });
 
 test("max with no arguments returns -Infinity", () => {
  assert.strictEqual(max(), -Infinity);
 });
 
 test("max propagates NaN if any argument is NaN", () => {
  assert.ok(Number.isNaN(max(NaN, 1, 2)), "Result should be NaN when NaN is present");
  assert.ok(Number.isNaN(max(5, NaN)), "Result should be NaN when NaN is present");
 });
 
 test("max correctly handles Infinity values", () => {
  assert.strictEqual(max(Infinity, 1, 2), Infinity);
  assert.strictEqual(max(-Infinity, -100, -200), -100);
 });
 
 test("max works with very large numbers without overflow", () => {
  const large1 = Number.MAX_SAFE_INTEGER;
  const large2 = Number.MAX_SAFE_INTEGER - 1;
  assert.strictEqual(max(large1, large2), large1);
 });